<?php
class Soul_Request_Result_Download extends Soul_Request_Result_Base {
	
	private $_fileName = NULL;
	private $_donwloadName = NULl;
	
	public function getDownloadName(){
		return $this->_donwloadName;
	}
	
	public function setDownloadName($value){
		$this->_donwloadName = $value;
		return $this;
	}
	
	public function getFileName(){
		return $this->_fileName;
	}
	
	public function setFileName($value){
		$this->_fileName = $value;
		return $this;
	}

    public function execute(){        
        $downloadName = $this->getDownloadName();
        if(is_null($downloadName)){
        	$downloadName = time().'_'.basename($this->getFileName());
        }

        header("Content-type:application/octet-stream");
        header("Accept-Ranges:bytes");
        header("Accept-Length:" . filesize($this->getFileName()));
        header("Content-Disposition:attachment;filename=".$downloadName);

        $fp = fopen($this->getFileName(), "r");
        $content = fread($fp, filesize($this->getFileName()));
        echo $content;
        Soul_Web_Factory::getResponse()->end();
    }
}